﻿/****************************** Module Header ******************************\
* Module Name:  UiWinCustomFunctions.cs
* Project:	    YR.CUIT.Framework
* Copyright (c) Yogaratnam Rahulan.
* 
* The class UiWinCustomFunctions is a win form custom functions Object which runs within windows Explorer and offers additional services.
* 
* A UiWinCustomFunctions is a dynamic-link library (DLL) capable of attaching itself to any new 
* instance of Internet Explorer or Windows Explorer. Such a module can get in touch 
* with the browser through the container's .  
* 
* This class is used to make the test automation easier and BDD/TDD manner development. It also supplies 
* functions to intracts with windows pop-up on IE.
* 
* This source is subject to the Yogaratnam Rahulan Public License.
* See Soon
* All other rights reserved.
* 
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using YR.CUIT.SearchFilterEngine;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using System;
using System.Diagnostics;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RY.CUIT.Framework
{
    public partial class UiWinCustomFunctions
    {
        #region config
        WinWindow _winApp;
        private ApplicationUnderTest _application;
        #endregion

        #region Pop window private functions
        private WinWindow GetPopWindow()
        {
            var chooseFileDialog = new WinWindow();
            var dialog = chooseFileDialog.Container.SearchAndFilterObjects<WinWindow>(new { ControlType = "Window", ClassName = "#32770" });
            dialog.TechnologyName = "MSAA";
            return dialog;
        }
        #endregion

        #region Launch & Clsoe application
        public WinWindow LaunchUrl(string path, string altpath)
        {
            return HandleExceptions(() =>
            {

                _application = ApplicationUnderTest.Launch(path, altpath);
                if (!_application.Maximized)
                {
                    _application.Maximized = true;
                }
                //get all the controls we want to use - this uses dynamic types for serach and filter properties
                _winApp = _application.SearchAndFilterObjects<WinWindow>(
                    /* pass search properties */
               new { Name = path },
                    /*pass filter properties if needed */
                new { ClassName = altpath });
                return _winApp;
            });
        }
        public void CloseApplicationUnderTest()
        {
            HandleExceptions(() =>
            {
                if (_application != null)
                {
                    _application.Close();
                }
            });
        }
        #endregion

        #region Locate winedit and do the actions
        public WinEdit LocateWinTxtBox(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinEdit(_winApp);
                _winApp.TechnologyName = "MSAA";

                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinEdit>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinEdit>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinEdit>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinEdit>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinEdit>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinTxtBox :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinEdit LocateWinTxtBoxAndEnterTxt(string id = "", string name = "", string classname = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinTxtBox(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Click(ctrl);
                    Keyboard.SendKeys(value);
                }
                return ctrl;
            });
        }
        public WinEdit LocateWinTxtBoxAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinTxtBox(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }

        public WinEdit LocateWinPopTxtBox(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var getWin = GetPopWindow();
                var ctrl = new WinEdit(getWin);
                if (getWin != null)
                {
                    getWin.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinEdit>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinEdit>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinEdit>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinEdit>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinEdit>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinPopTxtBox :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinEdit LocateWinPopTxtBoxAndEnterTxt(string id = "", string name = "", string classname = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopTxtBox(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                    ctrl.SetProperty(WinEdit.PropertyNames.Text, value);
                }
                return ctrl;
            });
        }
        public WinEdit LocateWinPopTxtBoxAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopTxtBox(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate win textt and do the actions
        public WinText LocateWinText(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinText(_winApp);
                _winApp.TechnologyName = "MSAA";

                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinText>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinText>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinText>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinText>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinText>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinText :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinText LocateWinTextAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinText(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinText LocateWinTextAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinText(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }

        public WinText LocateWinPopText(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var getWin = GetPopWindow();
                var ctrl = new WinText(getWin);
                if (getWin != null)
                {
                    getWin.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinText>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinText>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinText>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinText>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinText>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinPopText :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinText LocateWinPopTxtBoxAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopText(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinText LocateWinPopTextAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopText(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate WinButton and do the actions
        public WinButton LocateWinButton(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinButton(_winApp);
                _winApp.TechnologyName = "MSAA";

                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinButton>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinButton>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinButton LocateWinButtonAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinButtonAndPointClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }
        public WinButton LocateWinButtonAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinButtonAndPointHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }

        public WinButton LocateWinPopButton(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var ctrl = new WinButton(wWindow);
                wWindow.TechnologyName = "MSAA";

                if (wWindow != null)
                {
                    wWindow.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Name = name });
                    else if (name != string.Empty && classname != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Name = name, ClassName = classname });
                    else if (classname != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinPopButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopButtonAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopButtonAndPointHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopButtonAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopButtonAndPointClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }

        public WinButton LocateWinSecurityButton(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var ctrl = new WinButton();
                wWindow.TechnologyName = "MSAA";

                if (wWindow != null)
                {
                    wWindow.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Name = name });
                    else if (name != string.Empty && classname != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Name = name, ClassName = classname });
                    else if (classname != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = wWindow.Container.SearchAndFilterObjects<WinButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinSecurityButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinButton LocateWinSecurityButtonAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSecurityButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinSecurityButtonAndPointClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSecurityButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }
        public WinButton LocateWinSecurityButtonAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSecurityButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinSecurityButtonAndPointHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSecurityButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }

        public WinButton LocateWinPopFileuploadButton(string name = "", string classname = "", string displayTxt = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinButton(GetPopWindow());
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();

                    if (name != string.Empty)
                        ctrl.SearchProperties.Add(WinButton.PropertyNames.Name, name);
                    else if (displayTxt != string.Empty)
                        ctrl.SearchProperties.Add(WinButton.PropertyNames.DisplayText, displayTxt);
                    else if (classname != string.Empty)
                        ctrl.SearchProperties.Add(WinButton.PropertyNames.ClassName, classname);
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinPopFileuploadButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopFileuploadButtonAndHover(string name = "", string classname = "", string displayTxt = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopFileuploadButton(name: name, classname: classname, displayTxt: displayTxt);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinButton LocateWinPopFileuploadButtonAndClick(string name = "", string classname = "", string displayTxt = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopFileuploadButton(name: name, classname: classname, displayTxt: displayTxt);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }

        public WinSplitButton LocateWinSplitButton(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinSplitButton(_winApp);
                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinSplitButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinSplitButton>(new { Name = name });
                    else if (classname != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinSplitButton>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinSplitButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinSplitButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinSplitButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinSplitButtonAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSplitButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinSplitButtonAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinSplitButton(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }

        public WinSplitButton LocateWinPopSplitButton(string pid = "", string pname = "", string pclassname = "", string pinnertext = "", string ptitle = "", string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var getWin = LocateWinPopWindow(id: pid, name: pname, classname: pclassname, innertext: pinnertext, title: ptitle);
                var ctrl = new WinSplitButton(getWin);
                _winApp.TechnologyName = "MSAA";

                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { Name = name });
                    else if (name != string.Empty && classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { Name = name, ClassName = classname });
                    else if (classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinSplitButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinPopSplitButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinPopSplitButtonAndHover(string pid = "", string pname = "", string pclassname = "", string pinnertext = "", string ptitle = "", string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopSplitButton(pid: pid, pname: pname, pclassname: pclassname, pinnertext: pinnertext, ptitle: ptitle, id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinPopSplitButtonAndPointHover(string pid = "", string pname = "", string pclassname = "", string pinnertext = "", string ptitle = "", string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopSplitButton(pid: pid, pname: pname, pclassname: pclassname, pinnertext: pinnertext, ptitle: ptitle, id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinPopSplitButtonAndClick(string pid = "", string pname = "", string pclassname = "", string pinnertext = "", string ptitle = "", string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopSplitButton(pid: pid, pname: pname, pclassname: pclassname, pinnertext: pinnertext, ptitle: ptitle, id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinSplitButton LocateWinPopSplitButtonAndPointClick(string pid = "", string pname = "", string pclassname = "", string pinnertext = "", string ptitle = "", string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopSplitButton(pid: pid, pname: pname, pclassname: pclassname, pinnertext: pinnertext, ptitle: ptitle, id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }


        #endregion

        #region Locate WinWindow and do the actions
        public WinWindow LocateWinPopWindow(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinWindow(null);
                ctrl.TechnologyName = "MSAA";
                if (ctrl != null)
                {
                    ctrl.WaitForControlReady();
                    if (id != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { Name = name });
                    else if (name != string.Empty && classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { Name = name, ClassName = classname });
                    else if (classname != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { ClassName = classname });
                    else if (innertext != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = ctrl.Container.SearchAndFilterObjects<WinWindow>(new { Title = title });
                    ctrl.WaitForControlReady();

                }
                else
                {
                    Assert.Fail("LocateWinPopWindow :: Control not loaded");
                }
                return ctrl;
            });
        }
        public WinWindow LocateWinPopWindowAndHover(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopWindow(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinWindow LocateWinPopWindowAndClick(string id = "", string name = "", string classname = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinPopWindow(id: id, name: name, classname: classname, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate win combo box and do the actions
        public WinComboBox LocateWinComboBox(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = new WinComboBox(_winApp);
                _winApp.TechnologyName = "MSAA";

                if (_winApp != null)
                {
                    _winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinComboBox>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinComboBox>(new { Name = name });
                    else if (sclass != string.Empty)
                        ctrl = _winApp.SearchAndFilterObjects<WinComboBox>(new { Class = sclass });
                    else if (innertext != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinComboBox>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = _winApp.Container.SearchAndFilterObjects<WinComboBox>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinComboBox :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndSelect(string id = "", string name = "", string sclass = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                    ctrl.SelectedItem = value;
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndEnterTxt(string id = "", string name = "", string sclass = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                    Keyboard.SendKeys(value);
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndPointSelect(string id = "", string name = "", string sclass = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                    ctrl.SelectedItem = value;
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndPointHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                }
                return ctrl;
            });
        }
        public WinComboBox LocateWinComboBoxAndPointEnterTxt(string id = "", string name = "", string sclass = "", string innertext = "", string title = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinComboBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(new Point(ctrl.BoundingRectangle.X + 50, ctrl.BoundingRectangle.Y + 14));
                    Keyboard.SendKeys(value);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate check box and do the actions

        public WinCheckBox LocateWinCheckBox(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var winApp = new WinWindow();
                var ctrl = new WinCheckBox();
                winApp.TechnologyName = "MSAA";

                if (winApp != null)
                {
                    winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCheckBox>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCheckBox>(new { Name = name });
                    else if (sclass != string.Empty)
                        ctrl = winApp.SearchAndFilterObjects<WinCheckBox>(new { Class = sclass });
                    else if (innertext != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCheckBox>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCheckBox>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinCheckBox :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinCheckBox LocateWinCheckBoxAndChecked(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCheckBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.Checked = true;
                }
                return ctrl;
            });
        }
        public WinCheckBox LocateWinCheckBoxAndUnChecked(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCheckBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    ctrl.Checked = false;
                }
                return ctrl;
            });
        }
        public WinCheckBox LocateWinCheckBoxAndHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCheckBox(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate Win Radio button and do the actions
        public WinRadioButton LocateWinRadioButton(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var winApp = new WinWindow();
                var ctrl = new WinRadioButton();
                winApp.TechnologyName = "MSAA";

                if (winApp != null)
                {
                    winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinRadioButton>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinRadioButton>(new { Name = name });
                    else if (sclass != string.Empty)
                        ctrl = winApp.SearchAndFilterObjects<WinRadioButton>(new { Class = sclass });
                    else if (innertext != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinRadioButton>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinRadioButton>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinRadioButton :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinRadioButton LocateWinRadioButtonAndClick(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinRadioButton(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinRadioButton LocateWinRadioButtonAndHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinRadioButton(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate win tab and do the actions
        public WinTabPage LocateWinTabPage(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var winApp = new WinWindow();
                var ctrl = new WinTabPage();
                winApp.TechnologyName = "MSAA";

                if (winApp != null)
                {
                    winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinTabPage>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinTabPage>(new { Name = name });
                    else if (sclass != string.Empty)
                        ctrl = winApp.SearchAndFilterObjects<WinTabPage>(new { Class = sclass });
                    else if (innertext != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinTabPage>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinTabPage>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinTabPage :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinTabPage LocateWinTabPageAndClick(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinTabPage(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinTabPage LocateWinTabPageAndDoubleClick(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinTabPage(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.DoubleClick(ctrl);
                }
                return ctrl;
            });
        }
        public WinTabPage LocateWinTabPageAndHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinTabPage(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate win cell and do the actions
        public WinCell LocateWinCell(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var winApp = new WinWindow();
                var ctrl = new WinCell();
                winApp.TechnologyName = "MSAA";

                if (winApp != null)
                {
                    winApp.WaitForControlReady();

                    if (id != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCell>(new { Id = id });
                    else if (name != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCell>(new { Name = name });
                    else if (sclass != string.Empty)
                        ctrl = winApp.SearchAndFilterObjects<WinCell>(new { Class = sclass });
                    else if (innertext != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCell>(new { InnerText = innertext });
                    else if (title != string.Empty)
                        ctrl = winApp.Container.SearchAndFilterObjects<WinCell>(new { Title = title });
                    if (ctrl != null)
                    {
                        ctrl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinCell :: Control not loaded");
                    }
                }
                return ctrl;
            });
        }
        public WinCell LocateWinCellAndClick(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCell(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Click(ctrl);
                }
                return ctrl;
            });
        }
        public WinCell LocateWinCellAndDoubleClick(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCell(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.DoubleClick(ctrl);
                }
                return ctrl;
            });
        }
        public WinCell LocateWinCellAndHover(string id = "", string name = "", string sclass = "", string innertext = "", string title = "")
        {
            return HandleExceptions(() =>
            {
                var ctrl = LocateWinCell(id: id, name: name, sclass: sclass, innertext: innertext, title: title);
                if (ctrl != null)
                {
                    Mouse.Hover(ctrl);
                }
                return ctrl;
            });
        }
        #endregion

        #region Locate Oparatinf systems security popups and do the actions
        public UITestControl LocateWinSevenSecurityPopAndEnterTxt(string name = "", string className = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var winW = wWindow.Container.SearchAndFilterObjects<WinWindow>(new { Name = "Windows Security", ClassName = "#32770" });
                if (winW != null)
                {
                    winW.WaitForControlReady();
                    Mouse.Hover(winW);
                    var wl = new WinListItem(winW);
                    wl.SearchProperties.Add(WinListItem.PropertyNames.Name, "Use another account");
                    if (wl != null)
                    {
                        wl.WaitForControlReady();
                        var ctrl = new WinEdit(wl);
                        if (ctrl != null)
                        {
                            if (name != string.Empty)
                                ctrl = wl.Container.SearchAndFilterObjects<WinEdit>(new { Name = name });
                            else if (className != string.Empty)
                                ctrl = wl.SearchAndFilterObjects<WinEdit>(new { Class = className });
                            if (ctrl != null)
                            {
                                ctrl.WaitForControlReady();
                                Mouse.Click(ctrl);
                                Keyboard.SendKeys(value);
                            }
                            else
                            {
                                Assert.Fail("locateWinSevenSecurityPop :: Control not loaded");
                            }
                        }
                    }
                }
                return winW;
            });
        }
        public UITestControl LocateWinSevenSecurityWinTxt(string name = "", string className = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var winW = wWindow.Container.SearchAndFilterObjects<WinWindow>(new { Name = "Windows Security", ClassName = "#32770" });
                if (winW != null)
                {
                    winW.WaitForControlReady();
                    Mouse.Hover(winW);
                    var wl = new WinText(winW);
                    if (name != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.Name, name);
                    else if (className != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.ClassName, className);
                    if (wl != null)
                    {
                        wl.WaitForControlReady();
                    }
                    else
                    {
                        Assert.Fail("LocateWinSevenSecurityWinTxt :: Control not loaded");
                    }
                }
                return winW;
            });
        }
        public UITestControl LocateWinSevenSecurityWinTxtAndClick(string name = "", string className = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var winW = wWindow.Container.SearchAndFilterObjects<WinWindow>(new { Name = "Windows Security", ClassName = "#32770" });
                if (winW != null)
                {
                    winW.WaitForControlReady();
                    Mouse.Hover(winW);
                    var wl = new WinText(winW);
                    if (name != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.Name, name);
                    else if (className != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.ClassName, className);
                    if (wl != null)
                    {
                        wl.WaitForControlReady();
                        Mouse.Click(wl);
                    }
                    else
                    {
                        Assert.Fail("LocateWinSevenSecurityWinTxtAndClick :: Control not loaded");
                    }
                }
                return winW;
            });
        }
        public UITestControl LocateWinSevenSecurityWinTxtAndHover(string name = "", string className = "")
        {
            return HandleExceptions(() =>
            {
                var wWindow = new WinWindow(null);
                var winW = wWindow.Container.SearchAndFilterObjects<WinWindow>(new { Name = "Windows Security", ClassName = "#32770" });
                if (winW != null)
                {
                    winW.WaitForControlReady();
                    Mouse.Hover(winW);
                    var wl = new WinText(winW);
                    if (name != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.Name, name);
                    else if (className != string.Empty)
                        wl.SearchProperties.Add(WinText.PropertyNames.ClassName, className);
                    if (wl != null)
                    {
                        wl.WaitForControlReady();
                        Mouse.Hover(wl);
                    }
                    else
                    {
                        Assert.Fail("LocateWinSevenSecurityWinTxtAndHover :: Control not loaded");
                    }
                }
                return winW;
            });
        }
        public WinWindow LocateWinXpSecurityPopAndEnterTxt(string wSecName = "", string id = "", string name = "", string className = "", string value = "")
        {
            return HandleExceptions(() =>
            {
                var winW = _winApp.Container.SearchAndFilterObjects<WinWindow>(new { Name = wSecName, ClassName = "#32770" });
                if (winW != null)
                {
                    winW.WaitForControlReady();
                    var ui = new UITestControl(winW);
                    ui.SearchProperties.Add(WinWindow.PropertyNames.Instance, "2");
                    ui.SearchProperties.Add(WinWindow.PropertyNames.ControlId, "1003");
                    if (ui != null)
                    {
                        ui.WaitForControlReady();
                        var ctrl = new WinComboBox(ui);
                        if (ctrl != null)
                        {
                            _winApp.WaitForControlReady();
                            if (id != string.Empty)
                                ctrl = ui.Container.SearchAndFilterObjects<WinComboBox>(new { Id = id });
                            else if (name != string.Empty)
                                ctrl = ui.Container.SearchAndFilterObjects<WinComboBox>(new { Name = name });
                            else if (className != string.Empty)
                                ctrl = ui.Container.SearchAndFilterObjects<WinComboBox>(new { Class = className });
                            if (ctrl != null)
                            {
                                ctrl.WaitForControlReady();
                                Mouse.Click(ctrl);
                                Keyboard.SendKeys(value);
                            }
                            else
                            {
                                Assert.Fail("locateWinXpSecurityPopAndEnterTxt :: Control not loaded");
                            }
                        }
                    }
                }
                return winW;
            });
        }
        #endregion

        #region Set Focus on Active Window
        public UITestControl LocateWinFileUploadWindowAndClik(string strName)
        {
            WinWindow wWindow = new WinWindow(null);
            try
            {
                var winW = wWindow.Container.SearchAndFilterObjects<WinWindow>(new { Name = strName });
                winW.WaitForControlReady();
                if (winW != null)
                {
                    Mouse.Hover(winW);
                    Mouse.Click(new Point(winW.BoundingRectangle.X + 50, winW.BoundingRectangle.Y + 14));
                }
                return wWindow;
            }
            catch
            {
                throw new UITestControlNotFoundException(strName);
            }

        }
        #endregion

        #region Error handling
        private static T HandleExceptions<T>(Func<T> func)
        {
            try
            {
                return func();
            }
            catch (UITestControlNotFoundException ex)
            {
                Trace.WriteLine("UITestControlNotFoundException occurred: " + ex.Message);
                Trace.WriteLine("Stack Trace :" + ex.StackTrace);
                return default(T);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception occurred: " + ex.Message);
                Trace.WriteLine("Stack Trace :" + ex.StackTrace);
                return default(T);
            }
        }

        private static void HandleExceptions(Action action)
        {
            try
            {
                action();
            }
            catch (UITestControlNotFoundException ex)
            {
                Trace.WriteLine("UITestControlNotFoundException occurred: " + ex.Message);
                Trace.WriteLine("Stack Trace :" + ex.StackTrace);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception occurred: " + ex.Message);
                Trace.WriteLine("Stack Trace :" + ex.StackTrace);
            }
        }

        #endregion

    }
}
